package com.luomo.java.juc.cas;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author LiuMei
 * @date 2021-01-14.
 */
public class AtomicReferenceDemo {

    public static void main(String[] args) {
        AtomicReference<User> atomicReference = new AtomicReference<>();
        User z3 = new User("z3",22);
        User z4 = new User("z3",25);
        atomicReference.set(z3);
        System.out.println(atomicReference.compareAndSet(z3, z4)+"\t"+atomicReference.get().toString());
        System.out.println(atomicReference.compareAndSet(z3, z4)+"\t"+atomicReference.get().toString());
    }

}

@Data
@AllArgsConstructor
class User{
    String userName;
    int age;
}
